package com.google.gwt.sample.contacts.client.common;

import com.google.gwt.sample.contacts.shared.ContactDetails;

import java.util.ArrayList;

@SuppressWarnings("serial")
public class ContactsColumnDefinitionsImpl extends ArrayList<ColumnDefinition<ContactDetails>> {

    private static ContactsColumnDefinitionsImpl instance = null;

    public static ContactsColumnDefinitionsImpl getInstance() {
        if (instance == null) {
            instance = new ContactsColumnDefinitionsImpl();
        }

        return instance;
    }

    protected ContactsColumnDefinitionsImpl() {
        this.add(new ColumnDefinition<ContactDetails>() {
            @Override
            public void render(ContactDetails c, StringBuilder sb, int index) {
                sb.append("<input type='checkbox' action='SELECT' index='" + index + "'/>");
            }

            @Override
            public boolean isSelectable() {
                return true;
            }
        });

        this.add(new ColumnDefinition<ContactDetails>() {
            @Override
            public void render(ContactDetails c, StringBuilder sb, int index) {
                sb.append("<div action='CLICK' id='" + c.getDisplayName() + "' index='" + index + "'>" + c.getDisplayName() + "</div>");
            }

            @Override
            public boolean isClickable() {
                return true;
            }
        });
    }
}
